<?php
/*
	
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$plugin_name =$this->plugin_name;
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('pluginname'=>$plugin_name,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid);
	if(!empty($_RQ['batchid'])){
		$params['batchid']=trim($_RQ['batchid']);
		$return['params']['batchid']=trim($_RQ['batchid']);
	}
	if(!empty($_RQ['type'])){
		$params['type']=trim($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if(!empty($_RQ['listid'])){
		$params['listid']=trim($_RQ['listid']);
		$return['params']['listid']=$_RQ['listid'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=trim($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['workerid'])){
		$params['workerid']=trim($_RQ['workerid']);
		$return['params']['workerid']=$_RQ['workerid'];
	}
	if(!empty($_RQ['status'])){
		$params['status']=trim($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(!empty($_RQ['sn'])){
		$params['sn']='%'.trim($_RQ['sn']).'%';
		$return['params']['sn']=$_RQ['sn'];
	}
	$fields=array('id','mid','listid','createtime','codeid','batchid','workerid','orderid','pluginname','type','ordersn','remark','username','mobile','selfnumber','status');
	$list=pdo_getslice('jy_kabao_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){		
			$item['title'] = pdo_getcolumn('jy_kabao_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['listid']),'title');
			$item['sn'] = pdo_getcolumn('jy_kabao_batch_code',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['codeid']),'sn');
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['id']=$item['orderid'];
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['awardstatus'] =$this->awardstatus;	
	$return['htmls']=array(
		  'type' => 'list',
		  'tabs' => 
		  array(
            array('op' => 'list','title' => '兑奖列表',),
		  ),
		  'list' => array('data' => 'list','tip'=>'非实物商品，点击兑奖奖自动已经发放奖品！','delall' => false,'del_one' => false,'edit' => false,'list' => array(
			 array('name'=>'member','title'=>'客户','type'=>'member'),
			 array('name' => 'sn','type' => 'string','title' => '兑换码',),
			 array('name' => 'ordersn','type' => 'string','title' => '订单编号',),
			 array('name' => 'title','type' => 'string','title' => '卡包名称',),
				array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'batchtypes'),
				array('type'=>'select','name'=>'storeid','title'=>'绑定门店','options'=>'stores'),
				array('type'=>'select','name'=>'workerid','title'=>'绑定员工','options'=>'workers','option_title'=>'name'),
				array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'orderstatus'),
				array('name'=>'createtime','title'=>'创建时间','type'=>'time'),    
			 ),
			 'action'=>array(
				array('type'=>'href','action'=>'jy_weishop/order.detail/','title'=>'查看商品订单','show'=>array('orderid >'=>0)),
			)),
		 'search'=>array(
			array('name'=>'type','width'=>15,'title'=>'类型','type'=>'radio','options'=>'batchtypes'),
			array('type'=>'select','width'=>15,'name'=>'listid','title'=>'所属卡包','options'=>'kabaos'),
			array('type'=>'select','width'=>15,'name'=>'storeid','title'=>'绑定门店','options'=>'stores'),
			array('type'=>'select','width'=>15,'name'=>'workerid','title'=>'绑定员工','options'=>'workers','option_title'=>'name'),
			array('name'=>'sn','width'=>15,'title'=>'编号','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'orderstatus'),
		)
	);
	$return['orderstatus']=$this->orderstatus;
	$return['batchtypes']=$this->batchtypes;
	$return['kabaos']=pdo_getall('jy_kabao_list',array('pluginname'=>$plugin_name,'uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['stores']=pdo_getall('jy_yiliao_store',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['workers']=pdo_getall('jy_yiliao_worker',array('uniacid'=>$_SESSION['uniacid']),array('name','id'),'id');
	exi($return);
}